﻿using Compass.PurchaseService.Infrastructure;
using Compass.Wasm.Server.Services.Purchases;
using Compass.Wasm.Shared.Purchases;
using Compass.Wasm.Shared;
using System.ComponentModel.DataAnnotations;

namespace Compass.Wasm.Server.Controllers.Purchases;

[Route("api/[controller]")]
[ApiController]
[UnitOfWork(typeof(PurchaseDbContext))]
public class NavInvValuationController : ControllerBase
{
    #region ctor
    private readonly INavInvValuationService _service;

    public NavInvValuationController(INavInvValuationService service)
    {
        _service = service;
    }
    #endregion

    #region 基本增删改查
    [HttpGet("All")]
    public async Task<ApiResponse<IEnumerable<NavInvValuationDto>>> GetAll() => await _service.GetAllAsync();

    [HttpGet("{id}")]
    public async Task<ApiResponse<NavInvValuationDto>> GetSingle([RequiredGuid] Guid id) => await _service.GetSingleAsync(id);

    [HttpPost("Add")]
    public async Task<ApiResponse<NavInvValuationDto>> Add(NavInvValuationDto dto) => await _service.AddAsync(dto);

    [HttpPut("{id}")]
    public async Task<ApiResponse<NavInvValuationDto>> Update([RequiredGuid] Guid id, NavInvValuationDto dto) => await _service.UpdateAsync(id, dto);

    [HttpDelete("{id}")]
    public async Task<ApiResponse<NavInvValuationDto>> Delete([RequiredGuid] Guid id) => await _service.DeleteAsync(id);

    #endregion

    #region 扩展查询
    [HttpGet("Number")]
    public async Task<ApiResponse<NavInvValuationDto>> GetSingleByNumberAndMonth(string number,DateTime month) => await _service.GetSingleByNumberAndMonthAsync(number,month);
    //http://10.9.18.31/api/NavInvValuation/Number?number=xxxx&month=xxxx


    [HttpGet("Period")]
    public async Task<ApiResponse<IEnumerable<NavInvValuationDto>>> GetAllByNumberAndPeriod(string number,DateTime start, DateTime end) => await _service.GetAllByNumberAndPeriodAsync(number,start,end);
    //http://10.9.18.31/api/NavInvValuation/Period?number=xxxx&start=xxx&end=xxx

    [HttpGet("MonthlyValuations")]
    public async Task<ApiResponse<IEnumerable<NavMonthlyValuationDto>>> GetMonthlyValuations() => await _service.GetMonthlyValuationsAsync();
    //http://10.9.18.31/api/NavInvValuation/MonthlyValuations


    #endregion
}